# New ASM File
encounter:
.asciiz "\nA hostile "

attack:
.asciiz " attacks you"

initiative_fail:
.asciiz "\nEnemy strikes first!"

initiative_success:
.asciiz "\nYou strike first!"

enemy_hits:
.asciiz "\nEnemy strikes you for "

player_hits:
.asciiz "\nYou strike the enemy for "

damage:
.asciiz " damage."

damage_display:
.asciiz "\nPlayer's base damage is supposed to be: "

enemy_misses:
.asciiz "\nEnemy misses!"

player_misses:
.asciiz "\nYou missed!"

death:
.asciiz "\nYou have been slain."

victory:
.asciiz "\nYou have slain the enemy."

combat_menu:
.asciiz "\nWhat would you like to do?\n1. Attack 1\n2. Attack 2\n3. Attack 3\n4. ULTIMATE PUNCH"

player_health:
.asciiz "\nYour health is: "

player_levelhealth:
.asciiz "\nYour level 2 health is: "

enemy_health:
.asciiz "\nEnemy's health is: "

# define possible enemy classes
# enemyclass 1
random_enemyclass_one:
.asciiz "Tiger"
random_enemyclass_one_hp:
.word 0x00000045
# enemyclass 2
random_enemyclass_two:
.asciiz "Ocelot"
random_enemyclass_two_hp:
.word 0x00000065
# enemyclass 3
random_enemyclass_three:
.asciiz "Hazard"
random_enemyclass_three_hp:
.word 0x00000034
# enemyclass 4
random_enemyclass_four:
.asciiz "Orc"
random_enemyclass_four_hp:
.word 0x00000045
random_enemyclass_five:
.asciiz "Lab Troll"
random_enemyclass_five_hp:
.word 0x00000045

# define player level characteristics (hp)
# 1
playerlevel_one_hp:
.word 0x00000045
# 2
playerlevel_two_hp:
.word 0x00000055
# 3
playerlevel_three_hp:
.word 0x00000065
# 4
playerlevel_four_hp:
.word 0x00000075

# define player attacks
player_hitchance_one:
.word 0x00000003
player_basedamage_one:
.word 0x00000010
player_hitchance_two:
.word 0x00000003
player_basedamage_two:
.word 0x00000020
player_hitchance_three:
.word 0x00000003
player_basedamage_three:
.word 0x00000030
player_hitchance_four:
.word 0x00000008
player_basedamage_four:
.word 0x20000040

#player_hitchance:
#.word 0x00000005
#player_basedamage:
#.word 0x00000008

enemy_hitchance:
.word 0x00000004
enemy_basedamage:
.word 0x00000001

current_playerlevel_hp:
.word 0x00000045

current_enemyclass_hp:
.word 0x00000040

# are we going to war?!
combat_coinflip:
	#push $31
	move $s5, $31
	jal gen_random_one
	nop
	move $t0, $v0
	li $t1, 0x00000001
	# if it rolled a one, begin battle encounter
	beq $t0, $t1, select_playerlevel
	nop
	move $31, $s5
	jr $31
	nop

# establish player characteristics
select_playerlevel:
	# take in current playerlevel from game, using $s7
	# player level 1?
	li $t1, 0x00000001
	beq $s7, $t1, select_playerlevel_one
	nop
	# player level 2?
	li $t1, 0x00000002
	beq $s7, $t1, select_playerlevel_two
	nop
	# player level 3?
	li $t1, 0x00000003
	beq $s7, $t1, select_playerlevel_three
	nop
	# player level 4?
	li $t1, 0x00000004
	beq $s7, $t1, select_playerlevel_four
	nop
	j select_playerlevel
	nop

# for level, assign current hp
select_playerlevel_one:
	# player hp to $s1
	li $s1, playerlevel_one_hp
	lw $s1, 0($s1)
	#DEBUG
	# print player's current health	
	li $a0, player_health
	jal libplp_uart_write_string
	nop
	move $a0, $s1
	jal libplp_uart_write_value_b2
	nop	
	j select_enemyclass
	nop	
select_playerlevel_two:
	#DEBUG
	# print player's current health	
	li $a0, player_levelhealth
	jal libplp_uart_write_string
	nop
	# player hp to $s1
	li $s1, playerlevel_two_hp
	lw $s1, 0($s1)
	move $a0, $s1
	jal libplp_uart_write_value_b2
	nop	
	j select_enemyclass
	nop	
select_playerlevel_three:
	# player hp to $s1
	li $s1, playerlevel_three_hp
	lw $s1, 0($s1)
	j select_enemyclass
	nop	
select_playerlevel_four:
	# player hp to $s1
	li $s1, playerlevel_four_hp
	lw $s1, 0($s1)
	j select_enemyclass
	nop	

# WHO DARES TO RAISE HIS HAND AGAINST ME?
select_enemyclass:
	jal gen_random_f
	nop
	move $t2, $v0
	# is it class 1?
	li $t3, 0x00000001
	beq $t2, $t3, select_enemyclass_one
	nop
	# is it class 2?
	li $t3, 0x00000002
	beq $t2, $t3, select_enemyclass_two
	nop
	# is it class 3?
	li $t3, 0x00000003
	beq $t2, $t3, select_enemyclass_three
	nop
	# is it class 4?
	li $t3, 0x00000004
	beq $t2, $t3, select_enemyclass_four
	nop
	# none of these? ok try again
	# note: this could potentially be problematic.
	# if this is the "right" number of instructions
	# gen_random_f may never select 1-4
	j select_enemyclass
	nop

# if class one, set current enemy to class one's characteristics
select_enemyclass_one:
	li $s0, random_enemyclass_one_hp
	lw $s0, 0($s0)

	# display combat-begin string
	li $a0, encounter
	jal libplp_uart_write_string
	nop
	li $a0, random_enemyclass_one
	jal libplp_uart_write_string
	nop
	li $a0, attack
	jal libplp_uart_write_string
	nop
	# begin battle
	j round_one_fight
	nop
# if class two, set current enemy to class two's characteristics
select_enemyclass_two:
	li $s0, random_enemyclass_two_hp
	lw $s0, 0($s0)
	# display combat-begin string
	li $a0, encounter
	jal libplp_uart_write_string
	nop
	li $a0, random_enemyclass_two
	jal libplp_uart_write_string
	nop
	li $a0, attack
	jal libplp_uart_write_string
	nop
	# begin battle
	j round_one_fight
	nop
# if class three, set current enemy to class three's characteristics
select_enemyclass_three:
	li $s0, random_enemyclass_three_hp
	lw $s0, 0($s0)
	# display combat-begin string
	li $a0, encounter
	jal libplp_uart_write_string
	nop
	li $a0, random_enemyclass_three
	jal libplp_uart_write_string
	nop
	li $a0, attack
	jal libplp_uart_write_string
	nop
	# begin battle
	j round_one_fight
	nop
# if class four, set current enemy to class four's characteristics
select_enemyclass_four:
	li $s0, random_enemyclass_four_hp
	lw $s0, 0($s0)
	# display combat-begin string
	li $a0, encounter
	jal libplp_uart_write_string
	nop
	li $a0, random_enemyclass_four
	jal libplp_uart_write_string
	nop
	li $a0, attack
	jal libplp_uart_write_string
	nop
	# begin battle
	j round_one_fight
	nop

# BATTLE WAR BEGIN
round_one_fight:
	# load current characteristics
	# enemy hp to $s0
	#li $s0, current_enemyclass_hp
	#lw $s0, 0($s0)

	# roll for initiative
	jal gen_random_one
	nop
	move $t0, $v0
	li $t1, 0x00000001
	beq $t0, $t1, enemy_turn_begin
	nop
	j player_turn_begin
	nop

# OH NOES ENEMY HITS FIRST
enemy_turn_begin:
	li $a0, initiative_fail
	jal libplp_uart_write_string
	nop
	j enemy_hit
	nop

# GET 'IM
player_turn_begin:
	li $a0, initiative_success
	jal libplp_uart_write_string
	nop
	j player_turn
	nop

# does the enemy hit you
enemy_hit:
	#li $t0, enemy_hitchance
	#lw $t3, 0($t0)
	jal gen_random_f
	nop
	move $t1, $v0
	# if roll is > hitchance, call it a hit
	# jump to calculate damage
	slt $t2, $s4, $t1
	bne $t2, $0, enemy_damage
	# "50/50" chance to hit
	#jal gen_random_one
	#nop
	#beq $v0, $0, enemy_damage
	nop
	# otherwise, call it a miss
	li $a0, enemy_misses
	jal libplp_uart_write_string
	nop
	nop
	# progress to player turn
	j player_turn
	nop

# if so, how badly does it hurt
# this is currently set to hit for
# basedmg + 1d15
enemy_damage:	
	li $t0, enemy_basedamage
	lw $t3, 0($t0)
	jal gen_random_f
	nop
	move $t1, $v0
	# calc total damage
	# damage is stored in s3
	addu $s3, $t3, $t1
	# subtract from player health, store
	subu $s1, $s1, $s3
	# display result to user
	li $a0, enemy_hits
	jal libplp_uart_write_string
	nop
	move $a0, $s3
	jal libplp_uart_write_value_b2
	nop
	li $a0, damage
	jal libplp_uart_write_string
	nop
	# print player's current health	
	li $a0, player_health
	jal libplp_uart_write_string
	nop
	move $a0, $s1
	jal libplp_uart_write_value_b2
	nop
	# did the enemy kill you?
	# if 0 < health, set 1
	slt $t1, $0, $s1
	beq $0, $t1, player_death
	nop
	# if not, you get to fight back
	j player_turn
	nop

player_turn:
	#determine team/class for proper attack list
	# meta?
	li $t3, 0x00000001
	beq $s6, $t3, meta_combat_select
	nop
	# front?
	li $t3, 0x00000002
	beq $s6, $t3, front_combat_select
	nop
	# haz?
	li $t3, 0x00000003
	beq $s6, $t3, haz_combat_select
	nop
	# ex
	li $t3, 0x00000004
	beq $s6, $t3, ex_combat_select
	nop
	# test
	li $t3, 0x00000004
	beq $s6, $t3, test_combat_select
	nop



# do you hit the enemy
player_hit:
	jal gen_random_f
	nop
	move $t1, $v0
	# if roll is > hitchance, call it a hit
	# jump to calculate damage
	slt $t2, $s4, $t1
	bne $t2, $0, player_damage
	nop
	# otherwise, call it a miss
	li $a0, player_misses
	jal libplp_uart_write_string
	nop
	# progress to enemy turn
	j enemy_hit
	nop

# if so, how badly does it hurt
# this is currently set to hit for
# basedmg + 2d15
player_damage:
	jal gen_random_f
	nop
	move $t1, $v0
	# calc damage + 1d15
	addu $s3, $s3, $t1
	jal gen_random_f
	nop
	move $t1, $v0
	# calc damage + 1d15
	addu $s3, $s3, $t1
	# subtract from enemy health, store
	subu $s0, $s0, $s3
	# display result to user
	li $a0, player_hits
	jal libplp_uart_write_string
	nop
	move $a0, $s3
	jal libplp_uart_write_value_b2
	nop
	li $a0, damage
	jal libplp_uart_write_string
	nop
	# print enemy's current health	
	li $a0, enemy_health
	jal libplp_uart_write_string
	nop
	move $a0, $s0
	jal libplp_uart_write_value_b2
	nop
	# did you kill the enemy?
	# if 0 < health, set 1
	slt $t1, $0, $s0
	beq $0, $t1, return_to_story
	nop
	j enemy_hit
	nop

player_heal:
	# add heal points to current HP
	addu $s1, $s1, $s3
	j enemy_hit
	nop

player_damage_all:
	#hurt all
	subu $s0, $s0, $s3
	subu $s1, $s1, $s3
	j enemy_hit
	nop

player_damage_self:
	#hurt self
	subu $s1, $s1, $s3
	j enemy_hit
	nop

return_to_story:
	li $a0, victory
	jal libplp_uart_write_string
	nop
	# we pushed return register during the coinflip
	move $31, $s5
	#pop $31
	jr $31
	nop

player_death:
	li $a0, death
	jal libplp_uart_write_string
	nop